from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
from config import Config
from blueprints.male import male_bp
from blueprints.female import female_bp


def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    # 启用CORS
    CORS(app)

    # 注册蓝图
    app.register_blueprint(male_bp)
    app.register_blueprint(female_bp)

    # 根路由 - 返回前端页面
    @app.route('/')
    def index():
        # return render_template('index.html')
        return  jsonify({
            'message': '体能考核API服务',
            'version': '1.0.0',
        })
    # 健康检查
    @app.route('/health')
    def health():
        return jsonify({'status': 'healthy', 'message': '体能考核API服务运行正常'})

    # API信息
    @app.route('/api')
    def api_info():
        return jsonify({
            'message': '体能考核API服务',
            'version': '1.0.0',
            'endpoints': {
                '男生考核': '/api/male/calculate',
                '女生考核': '/api/female/calculate',
                '男生健康检查': '/api/male/health',
                '女生健康检查': '/api/female/health',
                '男生项目信息': '/api/male/projects',
                '女生项目信息': '/api/female/projects'
            }
        })

    return app


if __name__ == '__main__':
    app = create_app()
    app.run(
        host=app.config['HOST'],
        port=app.config['PORT'],
        debug=app.config['DEBUG']
    )